home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / lib / Gen / Gen_creat.awk < prev    next >
Encoding:
AWK Script  |  1993-02-06  |  7.2 KB  |  276 lines

  1. # ----------------------------------------------------------------
  2. #   FILE
  3. #    Gen_creator.awk
  4. #
  5. #   DESCRIPTION
  6. #       awk script for Gen_creator.sh
  7. #       (was originally included as argument to awk in Gen_creator.sh,
  8. #       but bash dropped core instead of procesing this) -- kai
  9. #
  10. # ----------------------------------------------------------------
  11. # ----------------
  12. #    initialize variables
  13. # ----------------
  14. BEGIN {
  15.     SAVEFS = FS;
  16.     ORS = " ";
  17.     OFS = "";
  18.     nc = 0;
  19. }
  20.  
  21. # ----------------
  22. #    first scan slots file and read in slot definitions
  23. #    generated by inherits.sh
  24. # ----------------
  25. FILENAME != "-" && /{/, /}/ {
  26.     if ($1 ~ /{/) {
  27.         newclass = 1;
  28.         next;
  29.     }
  30.     if (newclass == 1) {
  31.         s = 1;
  32.         slotclass = $2
  33.         numslots[ slotclass ] = $1
  34.         FS = ":";
  35.         newclass = 0;
  36. #        print FILENAME "--- " slotclass "\n" > "/dev/tty";
  37.         next;
  38.     }
  39.     if ($1 ~ /}/) {
  40.         FS = SAVEFS;
  41.         next;
  42.     }
  43.  
  44.     slots[ slotclass s ] = $1;
  45.     slotdefs[ slotclass s++ ] = $2;
  46.     next;
  47. }
  48.  
  49. # ----------------
  50. #    finished scanning slots file, now process stdin...
  51. #
  52. #    Here we have found the start of a new class definition.
  53. #    Get the class name and begin generating the Make creator.
  54. # ----------------
  55. { FS = SAVEFS; }
  56.     
  57. /class /,/{/ { 
  58.     class = substr($2,2,length($2)-2);
  59.  
  60. #    print FILENAME "*** " class "\n" > "/dev/tty";
  61.  
  62. # ----
  63. #   generate RInit initialization function
  64. # ----
  65.     print "\n/* ----------------";
  66.     print "\n *    RInit", class, " - Raw initializer for ", class;
  67.     print "\n * ";
  68.     print "\n *    This function just initializes the internal";
  69.     print "\n *    information in a node. ";
  70.     print "\n * ----------------";
  71.     print "\n */";
  72.     print "\nextern void RInit", class, "();";
  73.     print "\n";
  74.     print "\nvoid \n", "RInit", class, "(p)";
  75.     print "\nPointer p;";
  76.     print "\n{";
  77.     print "\n\textern void Out", class, "();";
  78.     print "\n\textern bool Equal", class, "();";
  79.     print "\n\textern bool Copy", class, "();";
  80.     print "\n\n\t", class, " node = (", class, ") p;\n";
  81.     print "\n\tnode->type = classTag(", class, ");";
  82.     print "\n\tnode->outFunc = Out", class, ";";
  83.     print "\n\tnode->equalFunc = Equal", class, ";";
  84.     print "\n\tnode->copyFunc =  Copy", class, ";";
  85.     print "\n\n\treturn;\n}\n";
  86.  
  87. # ----
  88. #   generate the Make creator
  89. # ----
  90.     print "\n/* ----------------";
  91.     print "\n *    Make creator function for ", class;
  92.     print "\n * ";
  93.     print "\n *    This function is in some sence \"broken\" because";
  94.     print "\n *    it takes parameters for only this nodes slots and";
  95.     print "\n *    leaves this nodes inherited slots uninitialized.";
  96.     print "\n * ";
  97.     print "\n *    This is here for backward compatibility with code";
  98.     print "\n *    that relies on this behaviour.";
  99.     print "\n * ----------------";
  100.     print "\n */";
  101.     print "\nextern ", class, " Make", class, "();";
  102.     print "\n";
  103.     print "\n", class, "\nMake", class, "(";
  104.     i = 0;
  105. }
  106.  
  107. # ----------------
  108. #    Now process all the lines inbetween the { and the }
  109. # ----------------
  110. /{/,/}/    {
  111.         if ($1 !~ /inherits/ && $1 !~ /struct/ && \
  112.         $1 !~ /class/ && $1 !~ /}/ ) {
  113.            type[i] = $1;
  114.         whole[i] = $0;
  115.         decl[i++] = $2;
  116.     }
  117.     
  118.     if ($1 ~ /struct/ ) {
  119.         type[i] = $1+$2 ;
  120.         whole[i] = $0;
  121.         decl[i++] = substr($3,2,length($3)-1);
  122.     }
  123. }
  124.  
  125. # ----------------
  126. #    Now generate the Make creator function, the Out, Equal
  127. #    and Copy functions, and the IMake and RMake creators.
  128. # ----------------
  129. /}/ {
  130.     for (x=0;x<i-1;x++)
  131.         print decl[x], ","
  132.     print decl[x]")\n"
  133.  
  134.     for (x=0;x<i;x++) 
  135.         print whole[x],";\n"
  136.         
  137.     print "\n{"
  138.     print "\n\t", class, " node = New_Node(", class, ");\n";
  139.     print"\n\tRInit", class, "(node);\n";
  140.  
  141.     for (x=0;x<i;x++)
  142.         print "\n\tset_", decl[x], "(node, ", decl[x], ");";
  143.  
  144.     print "\n\n\treturn(node);\n}\n";
  145.  
  146. # ----
  147. #   generate Out function
  148. # ----
  149.     print "\n/* ----------------";
  150.     print "\n *    Out function for ", class;
  151.     print "\n * ----------------";
  152.     print "\n */";
  153.     print "\nextern void Out", class, "();";
  154.     print "\n;";
  155.     print "\nvoid \nOut", class, "(str, node)"
  156.     print "\n\tStringInfo str;"
  157.     print "\n\t", class, "\tnode;"
  158.     print "\n{\n\tchar buf[100];"
  159.     print "\n#ifdef\tOut", class, "Exists"
  160.     print "\n\n\tappendStringInfo(str, \"#S(\");"
  161.     print "\n\t_out", class, "(str, node);"
  162.     print "\n\tappendStringInfo(str, \")\");"
  163.     print "\n\n#else\t/* Out", class, "Exists */"
  164.     print "\n\tsprintf(buf, \"#S(", class, " node at 0x%lx)\", node);\n"
  165.     print "\n\tappendStringInfo(str, buf);"
  166.     print "\n#endif\t/* Out", class, "Exists */"
  167.     print "\n}\n"
  168.  
  169. # ----
  170. #   generate Equal function
  171. # ----
  172.     print "\n/* ----------------";
  173.     print "\n *    Equal function for ", class;
  174.     print "\n * ----------------";
  175.     print "\n */";
  176.     print "\nextern bool Equal", class, "();";
  177.     print "\n";
  178.     print "\nbool\nEqual", class, "(a, b)";
  179.     print "\n\t", class, "\ta, b;";
  180.     print "\n{";
  181.     print "\n#ifdef\tEqual", class, "Exists";
  182.     print "\n\treturn ((bool) _equal", class, "(a, b));";
  183.     print "\n\n#else\t/* Equal", class, "Exists */";
  184.     print "\n\tprintf(\"Equal", class, " does not exist!\");\n";
  185.     print "\n\treturn (false);";
  186.     print "\n#endif\t/* Equal", class, "Exists */";
  187.     print "\n}\n";
  188.  
  189. # ----
  190. #   generate Copy function
  191. # ----
  192.     print "\n/* ----------------";
  193.     print "\n *    Copy function for ", class;
  194.     print "\n * ----------------";
  195.     print "\n */";
  196.     print "\nextern bool Copy", class, "();";
  197.     print "\n";
  198.     print "\nbool\nCopy", class, "(from, to, alloc)";
  199.     print "\n\t", class, "\tfrom;";
  200.     print "\n\t", class, "\t*to;\t/* return */";
  201.     print "\n\tchar *\t(*alloc)();";
  202.     print "\n{";
  203.     print "\n#ifdef\tCopy", class, "Exists";
  204.     print "\n\treturn ((bool) _copy", class, "(from, to, alloc));";
  205.     print "\n\n#else\t/* Copy", class, "Exists */";
  206.     print "\n\tprintf(\"Copy", class, " does not exist!\");\n";
  207.     print "\n\treturn (false);";
  208.     print "\n#endif\t/* Copy", class, "Exists */";
  209.     print "\n}\n";
  210.  
  211. # ----
  212. #   generate IMake creator
  213. # ----
  214.     print "\n/* ----------------";
  215.     print "\n *    IMake", class, " - Inherited Make creator for ", class;
  216.     print "\n * ";
  217.     print "\n *    This creator function takes a parameter";
  218.     print "\n *    for each slot in this class and each slot";
  219.     print "\n *    in all inherited classes.";
  220.     print "\n * ----------------";
  221.     print "\n */";
  222.     print "\nextern ", class, " IMake", class, "();";
  223.     print "\n";
  224.     print "\n", class, "\n", "IMake", class, "(";
  225.  
  226.     n = numslots[ class ];
  227.     if (n > 0) {
  228.         for (s=1; s<=n-1; s++)
  229.             print slots[ class s ], ",";
  230.         print slots[ class s ], ")\n";
  231.  
  232.         for (s=1; s<=n; s++)
  233.             print slotdefs[ class s ], ";\n";
  234.     } else {
  235.         print ")\n";
  236.     }
  237.  
  238.     print "\n{";
  239.     print "\n\t", class, " node = New_Node(", class, ");\n";
  240.     print "\n\tRInit", class, "(node);\n";
  241.     
  242.     if (n > 0) {
  243.         for (s=1; s<=n ; s++) {
  244.             slot = slots[ class s ];
  245.             print "\n\tset_", slot, "(node, ", slot, ");";
  246.         }
  247.     }
  248.     print "\n\n\treturn(node);\n}\n";
  249.  
  250. # ----
  251. #   generate RMake creator
  252. # ----
  253.     print "\n/* ----------------";
  254.     print "\n *    RMake", class, " - Raw Make creator for ", class;
  255.     print "\n * ";
  256.     print "\n *    This creator function does not initialize";
  257.     print "\n *    any of its slots..  This is left up to the";
  258.     print "\n *    calling routine.";
  259.     print "\n * ----------------";
  260.     print "\n */";
  261.     print "\nextern ", class, " RMake", class, "();";
  262.     print "\n";
  263.     print "\n", class, "\n", "RMake", class, "()";
  264.     print "\n{";
  265.     print "\n\t", class, " node = New_Node(", class, ");\n";
  266.     print "\n\tRInit", class, "(node);";
  267.     print "\n\n\treturn(node);\n}\n";
  268. }
  269.  
  270. # ----------------
  271. #    thats all folks
  272. # ----------------
  273. END {
  274.     print "\n/* end-of-file */\n"
  275. }
  276.